﻿<common:LayoutAwarePage
    xmlns:common="using:Microsoft.PlayerFramework.Samples.Common"
    x:Class="Microsoft.PlayerFramework.Samples.EntertainmentAppPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Microsoft.PlayerFramework.Samples"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:mmppf="using:Microsoft.PlayerFramework"
    mc:Ignorable="d">

    <Page.Resources>

        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="ms-appx:///Microsoft.PlayerFramework/themes/EntertainmentTheme.xaml"/>
                <!--<ResourceDictionary Source="ms-appx:///Microsoft.PlayerFramework/themes/Classic.xaml"/>-->
            </ResourceDictionary.MergedDictionaries>

            <mmppf:PlaylistPlugin x:Key="PlaylistPlugin">
                <mmppf:PlaylistPlugin.Playlist>
                    <mmppf:PlaylistItem
                    SourceUri="http://smf.blob.core.windows.net/samples/videos/bigbuck.mp4" 
                    mmppf:PlaylistItemMetadata.Title="Big Buck Bunny" 
                    mmppf:PlaylistItemMetadata.Thumbnail="http://smf.blob.core.windows.net/samples/videos/bigbuckbunny_small.jpg"
                    mmppf:PlaylistItemMetadata.Description="As a follow-up to the successful project Orange's &quot;Elephants Dream&quot;, the Blender Foundation initiated another open movie project."
                    mmppf:PlaylistItemMetadata.Duration="00:00:32"/>
                    <mmppf:PlaylistItem 
                    SourceUri="http://smf.blob.core.windows.net/samples/videos/wildlife.mp4" 
                    mmppf:PlaylistItemMetadata.Title="Wildlife" 
                    mmppf:PlaylistItemMetadata.Thumbnail="http://smf.blob.core.windows.net/samples/videos/wildlife_small.jpg"
                    mmppf:PlaylistItemMetadata.Description="Wildlife Video"
                    mmppf:PlaylistItemMetadata.Duration="00:00:32"/>
                </mmppf:PlaylistPlugin.Playlist>
            </mmppf:PlaylistPlugin>

            <mmppf:MulticastConverter x:Key="IsNotNull">
                <mmppf:MulticastConverter.Converters>
                    <mmppf:IsNullConverter/>
                    <mmppf:NotConverter/>
                    <mmppf:BoolToVisibilityConverter/>
                </mmppf:MulticastConverter.Converters>
            </mmppf:MulticastConverter>

            <mmppf:StringFormatConverter x:Key="TimeConverter" StringFormat="h\:mm\:ss" />

            <mmppf:PlaylistCommands x:Key="PlaylistCommands" PlaylistPlugin="{StaticResource PlaylistPlugin}"/>

        </ResourceDictionary>

    </Page.Resources>

    <Grid Style="{StaticResource LayoutRootStyle}">
        <mmppf:MediaPlayer x:Name="player" Grid.Row="1" IsSkipPreviousVisible="True" IsSkipNextVisible="True"
                           IsSkipAheadVisible="True"
                           IsSkipBackVisible="True"
                           IsRewindVisible="True"
                           IsFastForwardVisible="True"
                           >
            <mmppf:MediaPlayer.Plugins>
                <StaticResource ResourceKey="PlaylistPlugin"/>
            </mmppf:MediaPlayer.Plugins>
        </mmppf:MediaPlayer>
    </Grid>

    <Page.BottomAppBar>
        <AppBar x:Name="lowerAppBar" Background="{StaticResource AppBarBackgroundThemeBrush}">
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                <Button x:Name="ReplayButton" Style="{StaticResource AppBarButtonStyle}"/>
                <Button x:Name="CaptionSelectionButton" Style="{StaticResource AppBarButtonStyle}"/>
                <Button x:Name="AudioSelectionButton" Style="{StaticResource AppBarButtonStyle}"/>
            </StackPanel>
        </AppBar>
    </Page.BottomAppBar>
    <Page.TopAppBar>
        <AppBar x:Name="upperAppBar">
            <Grid DataContext="{StaticResource PlaylistPlugin}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>
                <ComboBox MinWidth="300" Grid.Column="1" FontSize="30" ItemsSource="{Binding Playlist}" SelectedItem="{Binding CurrentPlaylistItem, Mode=TwoWay}">
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                </Grid.RowDefinitions>
                                <TextBlock FontSize="22" Text="{Binding (mmppf:PlaylistItemMetadata.Title)}"/>
                                <Grid Grid.Row="1">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="Auto"/>
                                    </Grid.ColumnDefinitions>
                                    <TextBlock FontSize="16" Opacity=".65" HorizontalAlignment="Left" Width="200" TextTrimming="WordEllipsis" Text="{Binding (mmppf:PlaylistItemMetadata.Description)}"/>
                                    <TextBlock FontSize="16" Grid.Column="1" Opacity=".65" Text="{Binding (mmppf:PlaylistItemMetadata.Duration), Converter={StaticResource TimeConverter}}"/>
                                </Grid>
                            </Grid>
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>
                <StackPanel Grid.Column="3" Orientation="Horizontal">
                    <Button Command="{Binding PreviousPlaylistItemCommand, Source={StaticResource PlaylistCommands}}" Visibility="{Binding PreviousPlaylistItem, Converter={StaticResource IsNotNull}}">
                        <StackPanel DataContext="{Binding PreviousPlaylistItem}">
                            <Image MaxWidth="90" MaxHeight="60" Source="{Binding (mmppf:PlaylistItemMetadata.Thumbnail)}"/>
                            <TextBlock FontSize="14" Text="Previous Episode" Foreground="#88FFFFFF"/>
                        </StackPanel>
                    </Button>
                    <Button Command="{Binding NextPlaylistItemCommand, Source={StaticResource PlaylistCommands}}" Visibility="{Binding NextPlaylistItem, Converter={StaticResource IsNotNull}}">
                        <StackPanel DataContext="{Binding NextPlaylistItem}">
                            <Image MaxWidth="90" MaxHeight="60" Source="{Binding (mmppf:PlaylistItemMetadata.Thumbnail)}"/>
                            <TextBlock FontSize="14" Text="Next Episode" Foreground="#88FFFFFF"/>
                        </StackPanel>
                    </Button>
                </StackPanel>
            </Grid>
        </AppBar>
    </Page.TopAppBar>
</common:LayoutAwarePage>